package com.chenjiagou.flight.service;

import com.chenjiagou.flight.model.Airport;
import com.chenjiagou.flight.repository.AirportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class AirportService {

    @Autowired
    private AirportRepository airportRepository;

    public List<String> getAllAirportNames() {
        return airportRepository.findDistinctNamesOrderedByCode();
    }

    public void addAirport(Airport airport) {
        airportRepository.save(airport);
    }

    public Optional<Airport> getAirportByCode(String code) {
        return airportRepository.findByCode(code);
    }
}